<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddSomeColumnsToCouponCodes extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('coupon_codes', function (Blueprint $table) {
            $table->string('name')->comment('标题');
            $table->string('code')->comment('优惠码')->unique();
            $table->string('type')->comment('类型');
            $table->decimal('value')->comment('折扣值');
            $table->unsignedInteger('total')->comment('总数量');
            $table->unsignedInteger('used')->comment('已使用数量')->default(0);
            $table->decimal('min_amount', 10, 2)->comment('使用本优惠券最低订单金额');
            $table->dateTime('not_before')->comment('在这时间之前不可以用')->nullable();
            $table->dateTime('not_after')->comment('在这时间之后不可以用')->nullable();
            $table->boolean('enabled');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('coupon_codes', function (Blueprint $table) {
            $table->dropColumn('name');
            $table->dropColumn('code');
            $table->dropColumn('type');
            $table->dropColumn('value');
            $table->dropColumn('total');
            $table->dropColumn('used');
            $table->dropColumn('min_amount');
            $table->dropColumn('not_before');
            $table->dropColumn('not_after');
            $table->dropColumn('enabled');
        });
    }
}
